package com.dangdi.show.controller;
import com.aliyuncs.exceptions.ClientException;
import com.dangdi.show.service.ManagerService;
import com.dangdi.show.service.ShiroService;
import com.dangdi.show.service.WechatUserService;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.util.ResourceUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.*;

@Controller
public class ManagerController {
    @Autowired
    WechatUserService userService;
    @Resource
    ManagerService managerService;
    @Resource
    ShiroService shiroService;

    @RequestMapping("Main")
    public String Main(ModelMap map, HttpServletRequest request) {
        map.addAttribute("manager", request.getSession().getAttribute("manager"));
        return "pc/Main";
    }


    @RequestMapping("managerLoginOut")
    public String ManagerLoginOut() {
        Subject subject = SecurityUtils.getSubject();
        subject.logout();
        return "index";
    }

    @RequestMapping("main_index")
    public String main_index(ModelMap map, HttpServletRequest request) {
        return "pc/main_index";
    }

    @RequiresPermissions("FindAllManagerList")
    @ResponseBody
    @RequestMapping("FindAllManagerList")
    public Map<String, Object> FindAllManagerList(int page, int limit) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("code", 0);
        map.put("msg", "");
        map.put("count", managerService.FindAllManagerListCount());
//        map.put("data",managerService.FindAllManagerList((page-1)*page,page*limit));
        SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd  HH:mm:ss");
        List<Map<String, Object>> allManagerList = managerService.FindAllManagerList((page - 1) * limit, limit);
        for (int i = 0; i < allManagerList.size(); i++) {
            allManagerList.get(i).put("manager_addtime", sf.format((Date) allManagerList.get(i).get("manager_addtime")));
        }
        map.put("data", allManagerList);
        return map;
    }

    @RequiresPermissions("FindAllManagerList")
    @ResponseBody
    @RequestMapping("FindAllManagerList2")
    public Map<String, Object> FindAllManagerList2(int page, int limit) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("code", 0);
        map.put("msg", "");
        map.put("count", managerService.FindAllManagerList2Count());
//        map.put("data",managerService.FindAllManagerList((page-1)*page,page*limit));
        SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd  HH:mm:ss");
        List<Map<String, Object>> allManagerList = managerService.FindAllManagerList2((page - 1) * limit, limit);
        for (int i = 0; i < allManagerList.size(); i++) {
            allManagerList.get(i).put("manager_addtime", sf.format((Date) allManagerList.get(i).get("manager_addtime")));
        }
        map.put("data", allManagerList);
        return map;
    }

    @RequiresPermissions("FindAllManagerList")
    @RequestMapping("manager_list")
    public String manager_list(ModelMap map) {
        return "pc/manager_list";
    }

    @ResponseBody
    @RequiresPermissions("heimingdan")
    @RequestMapping("lahei")
    public Map<String, Object> lahei(HttpServletRequest request, int manager_id, int status) {
        Map<String, Object> map = new HashMap<String, Object>();
        Map<String, Object> manager = (Map<String, Object>) request.getSession().getAttribute("manager");
        managerService.lahei(manager_id, status);
        if (status == 1) {
            managerService.insertRecord("管理员黑名单", manager.get("manager_name").toString(), "管理员", "黑名单", "正常", managerService.FindManagerBymanagerId(manager_id).get("manager_tel").toString(), "状态恢复正常");
        } else if (status == -1) {
            managerService.insertRecord("管理员黑名单", manager.get("manager_name").toString(), "管理员", "正常", "黑名单", managerService.FindManagerBymanagerId(manager_id).get("manager_tel").toString(), "加入黑名单");
        }
        map.put("newStatus", status);
        map.put("code", 1);
        return map;
    }

    @RequiresPermissions("shanchuManager")
    @ResponseBody
    @RequestMapping("shanchu")
    public Map<String, Object> shanchu(HttpServletRequest request, int manager_id) {
        Map<String, Object> map = new HashMap<String, Object>();
        Map<String, Object> beforeManager = managerService.FindManagerBymanagerId(manager_id);
        Map<String, Object> manager = (Map<String, Object>) request.getSession().getAttribute("manager");
        managerService.shanchu(manager_id);
        beforeManager.remove("manager_password");
        managerService.insertRecord("删除管理员", manager.get("manager_name").toString(), "管理员", beforeManager.toString(), "", beforeManager.get("manager_tel").toString(), "删除管理员");
        map.put("code", 1);
        //  insert into manager (manager_name,manager_tel,manager_password,manager_status,manager_postion,manager_addrees,manager_photo,manager_sex,manager_remarks) select manager_name,manager_tel,manager_password,manager_status,manager_postion,manager_addrees,manager_photo,manager_sex,manager_remarks from manaher where manager_id=1;
        return map;
    }

    @RequiresPermissions("updateManager")
    @RequestMapping("findManagerInfo")
    public String findManagerInfo(HttpServletRequest request, ModelMap map, int manager_id) {
        map.addAttribute("objectManager", managerService.FindManagerBymanagerId(manager_id));
        request.getSession().setAttribute("objectManager", managerService.FindManagerBymanagerId(manager_id));
        return "pc/findManagerInfo";
    }

    @RequiresPermissions("updateManager")
    @ResponseBody
    @RequestMapping("opdateManagerPhoto")
    public Map<String, Object> opdateManagerPhoto(ModelMap mp, HttpServletRequest request, @RequestParam("file") MultipartFile file) throws FileNotFoundException {
        long t = new Date().getTime();
        String filePath = "";
        File path = new File(ResourceUtils.getURL("classpath:").getPath());
        if (!path.exists()) path = new File("");
        if (!file.isEmpty()) {
            filePath = path.getAbsolutePath() + "/static/img/managerPhoto/" + t + file.getOriginalFilename();
            try {
                file.transferTo(new File(filePath));
            } catch (IllegalStateException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        Map<String, Object> objectManager = (Map<String, Object>) request.getSession().getAttribute("objectManager");
        Map<String, Object> manager = (Map<String, Object>) request.getSession().getAttribute("manager");
        //   managerService.UpdateManagerPhoto((int)objectManager.get("manager_id"),"/img/managerPhoto/"+t+file.getOriginalFilename());
        managerService.insertRecord("修改管理员头像", manager.get("manager_name").toString(), "管理员", managerService.FindManagerBymanagerId((int) objectManager.get("manager_id")).get("manager_photo").toString(), "/img/managerPhoto/" + t + file.getOriginalFilename(), objectManager.get("manager_tel").toString(), "修改管理员头像");
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("code", 0);
        map.put("msg", "");
        Map<String, Object> m = new HashMap<String, Object>();
        m.put("src", "/img/managerPhoto/" + t + file.getOriginalFilename());
        map.put("data", m);
        if (objectManager.get("manager_id").equals(manager.get("manager_id"))) {
            request.getSession().setAttribute("manager", managerService.FindManagerBymanagerId((int) manager.get("manager_id")));
            mp.addAttribute("manager", request.getSession().getAttribute("manager"));
        }
        return map;
    }

    @RequiresPermissions("updateManager")
    @ResponseBody
    @RequestMapping("updateManagerInfo")
    public Map<String, Object> updateManagerInfo(HttpServletRequest request, String manager_sex, String manager_address, String manager_postion, String manager_password, String manager_tel, String manager_name) {
        Map<String, Object> map = new HashMap<String, Object>();
        Map<String, Object> objecManager = (Map<String, Object>) request.getSession().getAttribute("objectManager");
        Map<String, Object> manager = (Map<String, Object>) request.getSession().getAttribute("manager");
        managerService.updateManagerInfo(manager_name, manager_tel, manager_password, manager_postion, manager_address, manager_sex, (int) objecManager.get("manager_id"));
        objecManager.remove("manager_password");
        Map<String, Object> beforeManager = managerService.FindManagerBymanagerId((int) objecManager.get("manager_id"));
        beforeManager.remove("manager_password");
        managerService.insertRecord("修改管理员信息", manager.get("manager_name").toString(), "管理员", objecManager.toString(), beforeManager.toString(), objecManager.get("manager_tel").toString(), "修改管理信息");
        map.put("statusCode", 0);
        map.put("message", "修改成功！");
        return map;
    }

    @RequestMapping("manager_xiugai_geren_xinxi")
    public String manager_xiugai_geren_xinxi() {
        return "pc/manager_xiugai_geren_xinxi";
    }

    @RequiresPermissions("chakanManagerjuese")
    @RequestMapping("FindObjectManagerRolers_page")
    public String FindObjectManagerRolers_page(ModelMap map, HttpServletRequest request, int manager_id) {
        List<Map<String, Object>> allRoleList = managerService.FindallRoleList();
        List<Map<String, Object>> objectManagerRoleList = managerService.FindManagerRoleList(manager_id);
        for (int i = 0; i < allRoleList.size(); i++) {
            for (int k = 0; k < objectManagerRoleList.size(); k++) {
                if (allRoleList.get(i).get("r_name").equals(objectManagerRoleList.get(k).get("role_name"))) {
                    allRoleList.remove(i);
                }
            }
        }
        map.addAttribute("allRoleList", allRoleList);
        map.addAttribute("objectManagerRoleList", objectManagerRoleList);
        map.addAttribute("objectManager", managerService.FindManagerBymanagerId(manager_id));
        request.getSession().setAttribute("objectManager", managerService.FindManagerBymanagerId(manager_id));
        return "manager/object_manager_roles_page";
    }

    @RequiresPermissions("chakanManagerjuese")
    @ResponseBody
    @RequestMapping("FindObjectManagerRolers")
    public Map<String, Object> FindObjectManagerRolers(HttpServletRequest request) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("code", 0);
        map.put("msg", "");
        map.put("count", 1000);
        Map<String, Object> objecManager = (Map<String, Object>) request.getSession().getAttribute("objectManager");
        map.put("data", managerService.FindManagerRoleList((int) objecManager.get("manager_id")));
        return map;
    }

    @RequiresPermissions("shanchuManagerJuese")
    @ResponseBody
    @RequestMapping("shanchuRoleByRoleId")
    public Map<String, Object> shanchuRole(HttpServletRequest request, int role_id) {
        Map<String, Object> map = new HashMap<String, Object>();
        Map<String, Object> r = managerService.FindRByRoleId(role_id);
        managerService.shanchuRoleByRoleId(role_id);
        Map<String, Object> objecManager = (Map<String, Object>) request.getSession().getAttribute("objectManager");
        Map<String, Object> manager = (Map<String, Object>) request.getSession().getAttribute("manager");
        System.out.println(r);
        System.out.println(manager);
        System.out.println(objecManager);
        managerService.insertRecord("删除管理员角色", manager.get("manager_name").toString(), "管理员", r.get("r_name").toString(), "", objecManager.get("manager_tel").toString(), "删除管理员角色");
        map.put("code", 1);
        return map;
    }

    @RequiresPermissions("addRoleToManager")
    @RequestMapping("addRoleToObejectManager")
    public String addRole(HttpServletRequest request, ModelMap map, String r_name) {
        Map<String, Object> objectManager = (Map<String, Object>) request.getSession().getAttribute("objectManager");
        int manager_id = (int) objectManager.get("manager_id");
        managerService.addRoleToObjectManager(manager_id, r_name);
        Map<String, Object> manager = (Map<String, Object>) request.getSession().getAttribute("manager");
        managerService.insertRecord("给管理员添加角色", manager.get("manager_name").toString(), "管理员", "", r_name, managerService.FindManagerBymanagerId(manager_id).get("manager_tel").toString(), "给管理员添加角色");
        List<Map<String, Object>> allRoleList = managerService.FindallRoleList();
        List<Map<String, Object>> objectManagerRoleList = managerService.FindManagerRoleList(manager_id);
        for (int i = 0; i < allRoleList.size(); i++) {
            for (int k = 0; k < objectManagerRoleList.size(); k++) {
                if (allRoleList.get(i).get("r_name").equals(objectManagerRoleList.get(k).get("role_name"))) {
                    allRoleList.remove(i);
                }
            }
        }
        map.addAttribute("allRoleList", allRoleList);
        map.addAttribute("objectManagerRoleList", objectManagerRoleList);
        map.addAttribute("objectManager", managerService.FindManagerBymanagerId(manager_id));
        return "pc/object_manager_roles_page";
    }

    @RequiresPermissions("FindAllManagerList")
    @ResponseBody
    @RequestMapping("searchManager")
    public Map<String, Object> searchManager(String title, int page, int limit) {
        Map<String, Object> map = new HashMap<String, Object>();
//        System.out.println(limit);
//        System.out.println(page);
        map.put("code", 0);
        map.put("msg", "");
        map.put("count", managerService.searchManagerCount(title));
        SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd  HH:mm:ss");
        List<Map<String, Object>> searchManagerList = managerService.searchManager((page - 1) * limit, limit, title);
        for (int i = 0; i < searchManagerList.size(); i++) {
            searchManagerList.get(i).put("manager_addtime", sf.format((Date) searchManagerList.get(i).get("manager_addtime")));
        }
        map.put("data", searchManagerList);
        return map;
    }

    @ResponseBody
    @RequestMapping("updateThisPassword")
    public Map<String, Object> updateThisPassword(HttpServletRequest request, String manager_tel, String phoneCode, String manager_password, String newPassword1) {
        Map<String, Object> map = new HashMap<String, Object>();
        if (!request.getSession().getAttribute("phoneCodePhone").equals(manager_tel)) {
            map.put("code", -1);
            map.put("message", "此号码没有发送验证码");
            return map;
        }
        if (!request.getSession().getAttribute("phoneCode").equals(phoneCode)) {
            map.put("code", -1);
            map.put("message", "验证码不正确");
            return map;
        }
        Map<String, Object> manager = (Map<String, Object>) request.getSession().getAttribute("manager");
        if (!manager.get("manager_password").equals(manager_password)) {
            map.put("code", -1);
            map.put("message", "旧密码不正确");
            return map;
        }
        managerService.updateThisPassword(newPassword1, (int) manager.get("manager_id"));
        request.getSession().setAttribute("manager", managerService.FindManagerBymanagerId((int) manager.get("manager_id")));
        map.put("message", "修改成功");
        map.put("code", 1);
        return map;
    }


    @ResponseBody
    @RequestMapping("updateThisPhoneNum")
    public Map<String, Object> updateThisPhoneNum(HttpServletRequest request, String newPhone, String phoneCode, String manager_password) {
        Map<String, Object> map = new HashMap<String, Object>();
        if (!request.getSession().getAttribute("phoneCodePhone").equals(newPhone)) {
            map.put("code", -1);
            map.put("message", "此号码没有发送验证码");
            return map;
        }
        if (!request.getSession().getAttribute("phoneCode").equals(phoneCode)) {
            map.put("code", -1);
            map.put("message", "验证码不正确");
            return map;
        }
        Map<String, Object> manager = (Map<String, Object>) request.getSession().getAttribute("manager");
        if (!manager.get("manager_password").equals(manager_password)) {
            map.put("code", -1);
            map.put("message", "旧密码不正确");
            return map;
        }
        if (manager.get("manager_tel").equals(newPhone)) {
            map.put("code", -1);
            map.put("message", "新号码与原来的号码一直，请修改新的手机号码");
            return map;
        }
        if (shiroService.FindManagerByManagerTel(newPhone) != null) {
            map.put("code", -1);
            map.put("message", "此手机号已被使用");
            return map;
        }
        managerService.updateThisPhoneNum(newPhone, (int) manager.get("manager_id"));
        request.getSession().setAttribute("manager", managerService.FindManagerBymanagerId((int) manager.get("manager_id")));
        map.put("message", "修改成功");
        map.put("code", 1);
        return map;
    }


    @ResponseBody
    @RequestMapping("opdateThisManagerPhoto")
    public Map<String, Object> opdateThisManagerPhoto(ModelMap mp, HttpServletRequest request, @RequestParam("file") MultipartFile file) throws FileNotFoundException {
        long t = new Date().getTime();
        String filePath = "";
        File path = new File(ResourceUtils.getURL("classpath:").getPath());
        if (!path.exists()) path = new File("");
        if (!file.isEmpty()) {
            filePath = path.getAbsolutePath() + "/static/img/managerPhoto/" + t + file.getOriginalFilename();
            try {
                file.transferTo(new File(filePath));
            } catch (IllegalStateException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        Map<String, Object> manager = (Map<String, Object>) request.getSession().getAttribute("manager");
        managerService.UpdateManagerPhoto((int) manager.get("manager_id"), "/img/managerPhoto/" + t + file.getOriginalFilename());
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("code", 0);
        map.put("msg", "");
        Map<String, Object> m = new HashMap<String, Object>();
        m.put("src", "/img/managerPhoto/" + t + file.getOriginalFilename());
        map.put("data", m);
        request.getSession().setAttribute("manager", managerService.FindManagerBymanagerId((int) manager.get("manager_id")));
        mp.addAttribute("manager", request.getSession().getAttribute("manager"));
        return map;
    }

    @RequiresPermissions("addManager")
    @RequestMapping("add_managerPage")
    public String add_managerPage(HttpServletRequest request, ModelMap map) {
        return "pc/addManagerPage";
    }

    @ResponseBody
    @RequestMapping("addManager")
    public Map<String, Object> addManager(HttpServletRequest request, String manager_sex, String manager_address, String manager_postion, String manager_password, String manager_tel, String manager_name, String manager_photo) {
        Map<String, Object> map = new HashMap<String, Object>();
        //Map<String,Object>objecManager= (Map<String, Object>) request.getSession().getAttribute("objectManager");
        //    managerService.insertManager(manager_name,manager_tel,manager_password,manager_postion,manager_address,manager_sex);
        if (shiroService.FindManagerByManagerTel(manager_tel) != null) {
            map.put("statusCode", -1);
            map.put("message", "手机号码已被使用！");
            return map;
        }
        managerService.insertManager(manager_name, manager_tel, manager_password, manager_postion, manager_address, manager_photo, manager_sex);
        String s = "{manager_name=" + manager_name + ",manager_tel=" + manager_tel + ",manager_postion=" + manager_postion + ",manager_photo=" + manager_photo + ",manager_sex=" + manager_sex + "}";
        Map<String, Object> manager = (Map<String, Object>) request.getSession().getAttribute("manager");
        managerService.insertRecord("添加管理员", manager.get("manager_name").toString(), "管理员", "", s, manager_tel, "添加管理员");
        map.put("statusCode", 0);
        map.put("message", "添加成功！");
        return map;
    }


    @RequiresPermissions("addManager")
    @ResponseBody
    @RequestMapping("insertManagerPhoto")
    public Map<String, Object> insertManagerPhoto(ModelMap mp, HttpServletRequest request, @RequestParam("file") MultipartFile file) throws FileNotFoundException {
        long t = new Date().getTime();
        String filePath = "";
        File path = new File(ResourceUtils.getURL("classpath:").getPath());
        if (!path.exists()) path = new File("");
        if (!file.isEmpty()) {
            filePath = path.getAbsolutePath() + "/static/img/managerPhoto/" + t + file.getOriginalFilename();
            try {
                file.transferTo(new File(filePath));
            } catch (IllegalStateException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        Map<String, Object> manager = (Map<String, Object>) request.getSession().getAttribute("manager");
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("code", 0);
        map.put("msg", "");
        Map<String, Object> m = new HashMap<String, Object>();
        m.put("src", "/img/managerPhoto/" + t + file.getOriginalFilename());
        map.put("data", m);
        return map;
    }

    @RequiresPermissions("FindAllRoleList")
    @ResponseBody
    @RequestMapping("FindAllRoleList")
    public Map<String, Object> FindAllRoleList(HttpServletRequest request) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("code", 0);
        map.put("msg", "");
        map.put("count", 1000);
        // Map<String,Object>objecManager= (Map<String, Object>) request.getSession().getAttribute("objectManager");
        map.put("data", managerService.FindallRoleList());
        return map;
    }

    @RequiresPermissions("FindAllRoleList")
    @RequestMapping("roleManagementPage")
    public String roleManagementPage(HttpServletRequest request) {
        return "pc/roleManagement";
    }

    @RequiresPermissions("addRole")
    @RequestMapping("addRole")
    public String addRole(HttpServletRequest request, String r_name, String r_explain) {
        managerService.InsertRole(r_name, r_explain);
        Map<String, Object> manager = (Map<String, Object>) request.getSession().getAttribute("manager");
        managerService.insertRecord("添加角色", manager.get("manager_name").toString(), "角色", "", "{r_name=" + r_name + ",r_explain=" + r_explain + "}", r_explain, "添加角色");
        return "pc/roleManagement";
    }

    @RequiresPermissions("FindAllRoleList")
    @ResponseBody
    @RequestMapping("check_role_name")
    public Map<String, Object> check_role_name(HttpServletRequest request, String r_name) {
        Map<String, Object> map = new HashMap<String, Object>();
        if (managerService.FindRoleByR_name(r_name) != null) {
            map.put("statusCode", -1);
            map.put("message", "角色名已存在！");
            return map;
        }
        map.put("statusCode", 1);
        map.put("message", "添加成功");
        return map;
    }

    @RequiresPermissions("shanchuRoleByRId")
    @ResponseBody
    @RequestMapping("shanchuRoleByRId")
    public Map<String, Object> shanchuRoleByRId(HttpServletRequest request, int r_id) {
        Map<String, Object> map = new HashMap<String, Object>();
        Map<String, Object> r = managerService.FindRByRId(r_id);
        managerService.shanchuRoleByRId(r_id);
        Map<String, Object> manager = (Map<String, Object>) request.getSession().getAttribute("manager");
        managerService.insertRecord("删除角色", manager.get("manager_name").toString(), "角色", r.toString(), "", r.get("r_name").toString(), "删除角色");
        map.put("code", 1);
        return map;
    }

    @RequiresPermissions("jueseYongYouQuanXian")
    @RequestMapping("havePermissionListPage")
    public String havePermissionListPage(HttpServletRequest request, String r_name) {
        request.getSession().setAttribute("r_name", r_name);
        return "pc/havePermissionListPage";
    }

    @RequiresPermissions("jueseWeiYongYouQuanXian")
    @RequestMapping("notHavePermissionListPage")
    public String notHavePermissionListPage(HttpServletRequest request, String r_name) {
        request.getSession().setAttribute("r_name", r_name);
        return "pc/notHavePermissionListPage";
    }

    @RequiresPermissions("jueseWeiYongYouQuanXian")
    @ResponseBody
    @RequestMapping("FindNotHaverPermissionListByR_id")
    public Map<String, Object> FindNotHaverPermissionListByR_id(HttpServletRequest request, int page, int limit) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("code", 0);
        map.put("msg", "");
        map.put("count", 1000);
        map.put("data", managerService.FindNotHaverPermissionListByR_id(request.getSession().getAttribute("r_name").toString(), (page - 1) * limit, limit));
        return map;
    }

    @RequiresPermissions("jueseYongYouQuanXian")
    @ResponseBody
    @RequestMapping("FindHaverPermissionListByR_id")
    public Map<String, Object> FindHaverPermissionListByR_id(HttpServletRequest request, int page, int limit) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("code", 0);
        map.put("msg", "");
        map.put("count", 1000);
        map.put("data", managerService.FindHaverPermissionListByR_id(request.getSession().getAttribute("r_name").toString(), (page - 1) * limit, limit));
        return map;
    }

    @RequiresPermissions("addPermissionToRole")
    @ResponseBody
    @RequestMapping("addPermissionToRole")
    public Map<String, Object> addPermissionToRole(HttpServletRequest request, String p_name) {
        Map<String, Object> map = new HashMap<String, Object>();
        managerService.addPermissionToRole(p_name, request.getSession().getAttribute("r_name").toString());
        Map<String, Object> manager = (Map<String, Object>) request.getSession().getAttribute("manager");
        Map<String, Object> r = managerService.FindRByRname(request.getSession().getAttribute("r_name").toString());
        managerService.insertRecord("添加权限", manager.get("manager_name").toString(), "角色", "", managerService.FindPByPname(p_name).toString(), r.get("r_name").toString(), "添加权限");
        map.put("code", 1);
        return map;
    }

    @RequiresPermissions("shanchuPermissionByPermissionId")
    @ResponseBody
    @RequestMapping("shanchuPermissionByPermissionId")
    public Map<String, Object> shanchuPermissionByPermissionId(HttpServletRequest request, String p_name) {
        Map<String, Object> map = new HashMap<String, Object>();
        System.out.println(p_name);
        System.out.println(request.getSession().getAttribute("r_name").toString());
        managerService.shanchuPermissionByPermissionId(p_name, request.getSession().getAttribute("r_name").toString());
        Map<String, Object> manager = (Map<String, Object>) request.getSession().getAttribute("manager");
        managerService.insertRecord("删除权限", manager.get("manager_name").toString(), "角色", managerService.FindPByPname(p_name).toString(), "", managerService.FindPByPname(p_name).get("p_explain").toString(), "删除权限");
        map.put("code", 1);
        return map;
    }

    ////////////////////////////////////////////////////// session 中的objectRid是 r_name   //////////////////////////////////
    @RequiresPermissions("jueseYongYouQuanXian")
    @ResponseBody
    @RequestMapping("searchPermission")
    public Map<String, Object> searchPermission(HttpServletRequest request, String title, int page, int limit) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("code", 0);
        map.put("msg", "");
        map.put("count", 1000);
        map.put("data", managerService.searchPermission(title, request.getSession().getAttribute("r_name").toString(), (page - 1) * limit, limit));
        return map;
    }

    @RequiresPermissions("jueseWeiYongYouQuanXian")
    @ResponseBody
    @RequestMapping("searchPermission2")
    public Map<String, Object> searchPermission2(HttpServletRequest request, String title, int page, int limit) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("code", 0);
        map.put("msg", "");
        map.put("count", 1000);
        map.put("data", managerService.searchPermission2(title, request.getSession().getAttribute("r_name").toString(), (page - 1) * limit, limit));
        return map;
    }

    /*
    到这里权限录入完毕
     */
    @RequiresPermissions("FindAllRecordList")
    @RequestMapping("record_list_page")
    public String record_list(ModelMap map, HttpServletRequest request) {
        return "pc/record_list";
    }

    @RequiresPermissions("FindAllRecordList")
    @ResponseBody
    @RequestMapping("FindAllRecordList")
    public Map<String, Object> FindAllRecordList(HttpServletRequest request, String title, int page, int limit) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("code", 0);
        map.put("msg", "");
        map.put("count", managerService.FindAllRecordListCount());
        SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd  HH:mm:ss");
        List<Map<String, Object>> allRecordList = managerService.FindAllRecordList((page - 1) * limit, limit);
        for (int i = 0; i < allRecordList.size(); i++) {
            allRecordList.get(i).put("record_datetime", sf.format((Date) allRecordList.get(i).get("record_datetime")));
        }
        map.put("data", allRecordList);
        return map;
    }

    @RequiresPermissions("FindAllRecordList")
    @ResponseBody
    @RequestMapping("searchRecord")
    public Map<String, Object> searchRecord(String title, int page, int limit, String adate, String ddate) {
        Map<String, Object> map = new HashMap<String, Object>();
//        System.out.println(limit);
//        System.out.println(page);
        map.put("code", 0);
        map.put("msg", "");
        map.put("count", 1000);
        SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd  HH:mm:ss");
        List<Map<String, Object>> searchRecordList = new ArrayList<Map<String, Object>>();
        if (adate.equals("") || ddate.equals("")) {
            searchRecordList = managerService.searchRecordNoDate((page - 1) * limit, limit, title);
        } else {
            searchRecordList = managerService.searchRecord((page - 1) * limit, limit, title, adate, ddate);
        }

        for (int i = 0; i < searchRecordList.size(); i++) {
            searchRecordList.get(i).put("record_datetime", sf.format((Date) searchRecordList.get(i).get("record_datetime")));
        }
        map.put("data", searchRecordList);
        return map;
    }

    //按照角色查看用户
    @RequiresPermissions("findManagerByRName")
    @RequestMapping("findManagerByRNamePage")
    public String findManagerByRNamePage(HttpServletRequest request, String r_name) {
        request.getSession().setAttribute("r_name", r_name);
        return "pc/findManagerByRNamePage";
    }

    @RequiresPermissions("findManagerByRName")
    @ResponseBody
    @RequestMapping("findManagerByRName")
    public Map<String, Object> findManagerByRName(HttpServletRequest request, int page, int limit) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("code", 0);
        map.put("msg", "");
        map.put("count", 1000);
        map.put("data", managerService.findManagerByRName(request.getSession().getAttribute("r_name").toString(), (page - 1) * limit, limit));
        return map;
    }

    @RequiresPermissions("shanchuManagerJuese")
    @ResponseBody
    @RequestMapping("quxiaoManagerRole")
    public Map<String, Object> quxiaoManagerRole(HttpServletRequest request, int manager_id, String r_name) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("code", managerService.quxiaoManagerRole(manager_id, r_name));
        Map<String, Object> manager = (Map<String, Object>) request.getSession().getAttribute("manager");
        Map<String, Object> objecManager = managerService.FindManagerBymanagerId(manager_id);
        managerService.insertRecord("取消管理员的角色", manager.get("manager_name").toString(), "管理员", r_name, "", objecManager.get("manager_tel").toString(), "修改管理角色");
        return map;
    }

    //省份管理
    @RequiresPermissions("shengfenPage")
    @RequestMapping("shengfenPage")
    public String shengfenPage(ModelMap map, HttpServletRequest request) {
        return "pc/shengfenPage";
    }

    //城市管理
    @RequiresPermissions("chengshiPage")
    @RequestMapping("chengshiPage")
    public String chengshiPage(ModelMap map, HttpServletRequest request) {
        return "pc/chengshiPage";
    }

    //区域管理
    @RequiresPermissions("quyuPage")
    @RequestMapping("quyuPage")
    public String quyuPage(ModelMap map, HttpServletRequest request) {
        return "pc/quyuPage";
    }

    //获取省份列表
    @RequiresPermissions("shengfenPage")
    @ResponseBody
    @RequestMapping("getProvinceList")
    public Map<String, Object> getProvinceList(HttpServletRequest request, int page, int limit) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("code", 0);
        map.put("msg", "");
        map.put("count", 999999);
        map.put("data", managerService.getProvinceList((page - 1) * limit, limit));
        return map;
    }

    //获取城市列表
    @RequiresPermissions("chengshiPage")
    @ResponseBody
    @RequestMapping("getChengshiList")
    public Map<String, Object> getChengshiList(HttpServletRequest request, int page, int limit) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("code", 0);
        map.put("msg", "");
        map.put("count", 999999);
        map.put("data", managerService.getCityList((page - 1) * limit, limit));
        return map;
    }

    //获取区域列表
    @RequiresPermissions("quyuPage")
    @ResponseBody
    @RequestMapping("getQuyuList")
    public Map<String, Object> getQuyuList(HttpServletRequest request, int page, int limit) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("code", 0);
        map.put("msg", "");
        map.put("count", 99999);
        map.put("data", managerService.getAreaList((page - 1) * limit, limit));
        return map;
    }

    //搜索省份
    @RequiresPermissions("shengfenPage")
    @ResponseBody
    @RequestMapping("searchShengfen")
    public Map<String, Object> searchShengfen(HttpServletRequest request, String title, int page, int limit) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("code", 0);
        map.put("msg", "");
        map.put("count", 99999);
        map.put("data", managerService.searchShengfen(title, (page - 1) * limit, limit));
        return map;
    }

    //搜索城市
    @RequiresPermissions("chengshiPage")
    @ResponseBody
    @RequestMapping("searchChengshi")
    public Map<String, Object> searchChengshi(HttpServletRequest request, String title, int page, int limit) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("code", 0);
        map.put("msg", "");
        map.put("count", 99999);
        map.put("data", managerService.searchChengshi(title, (page - 1) * limit, limit));
        return map;
    }

    //筛选城市
    @RequiresPermissions("chengshiPage")
    @ResponseBody
    @RequestMapping("filterChengshi")
    public Map<String, Object> filterChengshi(HttpServletRequest request, int title, int page, int limit) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("code", 0);
        map.put("msg", "");
        map.put("count", 99999);
        if (title == 0) {
            map.put("data", managerService.getCityList((page - 1) * limit, limit));
            return map;
        }
        map.put("data", managerService.filterChengshi(title, (page - 1) * limit, limit));
        return map;
    }

    //筛选区域
    @RequiresPermissions("quyuPage")
    @ResponseBody
    @RequestMapping("filterArea")
    public Map<String, Object> filterArea(HttpServletRequest request, int title, int page, int limit) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("code", 0);
        map.put("msg", "");
        map.put("count", 99999);
        if (title == 0) {
            map.put("data", managerService.getAreaList((page - 1) * limit, limit));
            return map;
        }
        map.put("data", managerService.filterArea(title, (page - 1) * limit, limit));
        return map;
    }


    //搜索区域
    @RequiresPermissions("quyuPage")
    @ResponseBody
    @RequestMapping("searchArea")
    public Map<String, Object> searchArea(HttpServletRequest request, String title, int page, int limit) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("code", 0);
        map.put("msg", "");
        map.put("count", 99999);
        map.put("data", managerService.searchArea(title, (page - 1) * limit, limit));
        return map;
    }

    //删除省份
    @RequiresPermissions("shanchuShengfen")
    @ResponseBody
    @RequestMapping("shanchuShengfen")
    public Map<String, Object> shanchuShengfen(HttpServletRequest request, int province_id) {
        Map<String, Object> map = new HashMap<String, Object>();
        int row = managerService.shanchuShengfen(province_id);
        if (row > 0) {
            map.put("code", 1);
            map.put("msg", "删除成功");
            Map<String, Object> manager = (Map<String, Object>) request.getSession().getAttribute("manager");
//            managerService.insertRecord("删除省份",manager.get("manager_name").toString(),"管理员",managerService.,"","","删除管理区域");
            return map;
        } else {
            map.put("code", -1);
            map.put("msg", "删除失败");
        }
        return map;
    }

    //删除城市
    @RequiresPermissions("shanchuChengshi")
    @ResponseBody
    @RequestMapping("shanchuChengshi")
    public Map<String, Object> shanchuChengshi(HttpServletRequest request, int city_id) {
        Map<String, Object> map = new HashMap<String, Object>();
        int row = managerService.shanchuChengshi(city_id);
        if (row > 0) {
            map.put("code", 1);
            map.put("msg", "删除成功");
            return map;
        } else {
            map.put("code", -1);
            map.put("msg", "删除失败");
        }
        return map;
    }

    //删除城市
    @RequiresPermissions("shanchuQuyu")
    @ResponseBody
    @RequestMapping("shanchuQuyu")
    public Map<String, Object> shanchuQuyu(HttpServletRequest request, int area_id) {
        Map<String, Object> map = new HashMap<String, Object>();
        int row = managerService.shanchuQuyu(area_id);
        if (row > 0) {
            map.put("code", 1);
            map.put("msg", "删除成功");
            return map;
        } else {
            map.put("code", -1);
            map.put("msg", "删除失败");
        }
        return map;
    }

    //添加省份
    @RequiresPermissions("addShengfen")
    @RequestMapping("addShengfen")
    public String addShengfen(HttpServletRequest request, String shengfen) {
        int row = managerService.addShengfen(shengfen);
        return "pc/shengfenPage";
    }

    //check省份
    @RequiresPermissions("addShengfen")
    @ResponseBody
    @RequestMapping("check_shengfen")
    public Map<String, Object> check_shengfen(HttpServletRequest request, String shengfen) {
        Map<String, Object> map = new HashMap<String, Object>();
        System.out.println(shengfen);
        int row = managerService.check_shengfen(shengfen);
        System.out.println(row);
        if (row > 0) {
            map.put("statusCode", -1);
            map.put("message", shengfen + " 已存在");
            return map;
        } else {
            map.put("statusCode", 1);
        }
        return map;
    }

    //添加城市
    @RequiresPermissions("addCity")
    @RequestMapping("addCity")
    public String addCity(HttpServletRequest request, String city_name, int shengfen_id) {
        int row = managerService.addCity(shengfen_id, city_name);
        return "pc/chengshiPage";
    }

    //添加区域
    @RequiresPermissions("addArea")
    @RequestMapping("addArea")
    public String addArea(HttpServletRequest request, String area_name, int city_id) {
        int row = managerService.addArea(city_id, area_name);
        return "pc/quyuPage";
    }

    //check城市
    @RequiresPermissions("addCity")
    @ResponseBody
    @RequestMapping("check_city")
    public Map<String, Object> check_city(HttpServletRequest request, String city_name) {
        Map<String, Object> map = new HashMap<String, Object>();
        int row = managerService.check_city(city_name);
        if (row > 0) {
            map.put("statusCode", -1);
            map.put("message", city_name + " 已存在");
            return map;
        } else {
            map.put("statusCode", 1);
        }
        return map;
    }


    //check区域
    @RequiresPermissions("addArea")
    @ResponseBody
    @RequestMapping("check_area")
    public Map<String, Object> check_area(HttpServletRequest request, String area_name) {
        Map<String, Object> map = new HashMap<String, Object>();
        int row = managerService.check_area(area_name);
        if (row > 0) {
            map.put("statusCode", -1);
            map.put("message", area_name + " 已存在");
            return map;
        } else {
            map.put("statusCode", 1);
        }
        return map;
    }

    //轮播图管理
    @RequiresPermissions("wechat_index_lunbo")
    @RequestMapping("index_lunbo_page")
    public String index_lunbo_page(ModelMap map, HttpServletRequest request) {
        map.addAttribute("imgs", userService.getIndex_side_imgS());
        return "pc/index_lunbo_page";
    }

    //海报图图管理
    @RequiresPermissions("wechat_index_haibao")
    @RequestMapping("index_haibao_page")
    public String index_haibao_page(ModelMap map, HttpServletRequest request) {
        map.addAttribute("img", managerService.getIndexHaiBaoTu());
        return "pc/index_haibao_page";
    }

    //活动管理
    @RequiresPermissions("wechat_index_huodong")
    @RequestMapping("index_huodong_page")
    public String index_huodong_page(ModelMap map, HttpServletRequest request) {
        map.addAttribute("img", managerService.getIndexHuodong());
        return "pc/index_huodong_page";
    }

    //删除轮播图
    @RequiresPermissions("delete_index_lunbo")
    @RequestMapping("delete_index_lunbo")
    public String delete_index_lunbo(ModelMap map, HttpServletRequest request, int index_side_id) {
        int row = managerService.delete_lunbo_img(index_side_id);
        map.addAttribute("imgs", userService.getIndex_side_imgS());
        if (row == 1) {
            map.addAttribute("msg", sendAldert("删除成功！"));
        }
        return "pc/index_lunbo_page";
    }

    public String sendAldert(String s) {
        String msg = "<script>layer.alert('" + s + "');</script>";
        return msg;
    }

    //上传首页轮播图片
    @RequiresPermissions("upload_index_lunbo_img")
    @ResponseBody
    @RequestMapping("upload_index_lunbo_img")
    public Map<String, Object> upload_index_lunbo_img(int id, MultipartFile file) throws FileNotFoundException {
        long t = new Date().getTime();
        String filePath = "";
        File path = new File(ResourceUtils.getURL("classpath:").getPath());
        if (!path.exists()) path = new File("");
        if (!file.isEmpty()) {
            filePath = path.getAbsolutePath() + "/static/img/IndexSidePhoto/" + t + file.getOriginalFilename();
            try {
                file.transferTo(new File(filePath));
            } catch (IllegalStateException e) {
                // TODO Auto-generated catch block
                System.out.println(e);
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                System.out.println(e);
                e.printStackTrace();
            }
        }
        managerService.upload_index_lunbo_img(t + file.getOriginalFilename(), id);
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("code", 0);
        map.put("msg", "");
        return map;
    }

    //上传海报图标
    @RequiresPermissions("upload_index_haibao_img")
    @ResponseBody
    @RequestMapping("upload_index_haibao_img")
    public Map<String, Object> upload_index_haibao_img(MultipartFile file) throws FileNotFoundException {
        long t = new Date().getTime();
        String filePath = "";
        System.out.println(file.getOriginalFilename());
        File path = new File(ResourceUtils.getURL("classpath:").getPath());
        if (!path.exists()) path = new File("");
        if (!file.isEmpty()) {
            filePath = path.getAbsolutePath() + "/static/img/IndexHaiBaoPhoto/" + t + file.getOriginalFilename();
            try {
                file.transferTo(new File(filePath));
            } catch (IllegalStateException e) {
                // TODO Auto-generated catch block
                System.out.println(e);
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                System.out.println(e);
                e.printStackTrace();
            }
        }
        int row = managerService.upload_index_haibao_img(t + file.getOriginalFilename());
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("code", 0);
        map.put("msg", "");
        return map;
    }

    @RequiresPermissions("wechat_index_huodong")
    @ResponseBody
    @RequestMapping("upload_index_huodong_img_path")
    public Map<String, Object> upload_index_huodong_img(MultipartFile file, HttpServletRequest request) throws FileNotFoundException {
        long t = new Date().getTime();
        String filePath = "";
        File path = new File(ResourceUtils.getURL("classpath:").getPath());
        if (!path.exists()) path = new File("");
        if (!file.isEmpty()) {
            filePath = path.getAbsolutePath() + "/static/img/IndexHuoDongPhoto/" + t + file.getOriginalFilename();
            try {
                file.transferTo(new File(filePath));
            } catch (IllegalStateException e) {
                // TODO Auto-generated catch block
                System.out.println(e);
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                System.out.println(e);
                e.printStackTrace();
            }
        }
        int row;
        if (managerService.getIndexHuodong() == null) {
            row = managerService.upload_index_huodong_img2(t + file.getOriginalFilename(), null);
        } else {
            row = managerService.upload_index_huodong_img(t + file.getOriginalFilename(), null);
        }
        request.getSession().setAttribute("huodongImgUrl", t + file.getOriginalFilename());
        Map<String, Object> map = new HashMap<String, Object>();
        if (row != 1) {
            map.put("code", -1);
            map.put("msg", "修改失败！");
            return map;
        }
        map.put("code", 0);
        map.put("msg", "修改成功！");
        return map;
    }

    @RequiresPermissions("wechat_index_huodong")
    @ResponseBody
    @RequestMapping("upload_index_huodong_img_insert")
    public Map<String, Object> upload_index_huodong_img_insert(HttpServletRequest request, String title) throws FileNotFoundException {
        Map<String, Object> map = new HashMap<String, Object>();
        int row;
        if (request.getSession().getAttribute("huodongImgUrl") == null) {
            if (managerService.getIndexHuodong().get("index_huodong_img") == null) {
                row = managerService.upload_index_huodong_img2(null, title);
                if (row == 1) {
                    map.put("code", 0);
                    map.put("msg", "修改成功！");
                    return map;
                }
            } else {
                row = managerService.upload_index_huodong_img(managerService.getIndexHuodong().get("index_huodong_img").toString(), title);
                if (row == 1) {
                    map.put("code", 0);
                    map.put("msg", "修改成功！");
                    return map;
                }
            }
        } else {
            if (managerService.getIndexHuodong().get("index_huodong_img") == null) {
                row = managerService.upload_index_huodong_img2(request.getSession().getAttribute("huodongImgUrl").toString(), title);
                if (row == 1) {
                    map.put("code", 0);
                    map.put("msg", "修改成功！");
                    return map;
                }
            } else {
                row = managerService.upload_index_huodong_img(request.getSession().getAttribute("huodongImgUrl").toString(), title);
                if (row == 1) {
                    map.put("code", 0);
                    map.put("msg", "修改成功！");
                    return map;
                }
            }
        }
        map.put("code", -1);
        map.put("msg", "修改失败！");
        return map;
    }

    @RequiresPermissions("getPublishList")
    @ResponseBody
    @RequestMapping("getPublishList")
    public Map<String, Object> getPublishList(int page, int limit) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("code", 0);
        map.put("msg", "获取成功");
        map.put("count", managerService.getPublishListCount());
        map.put("data", managerService.getPublishList((page - 1) * limit, limit));
        return map;
    }

    @RequiresPermissions("getPublishList")
    @ResponseBody
    @RequestMapping("getSceneList")
    public Map<String, Object> getSceneList(int page, int limit) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("code", 0);
        map.put("msg", "获取成功");
        map.put("count", managerService.getSceneListCount());
        map.put("data", managerService.getScenehList((page - 1) * limit, limit));
        return map;
    }

    @RequiresPermissions("getPublishList")
    @RequestMapping("publish_list_page")
    public String publish_list_page() {
        return "pc/publish_list";
    }

    @RequiresPermissions("getPublishList")
    @RequestMapping("index_sceneList_page")
    public String index_sceneList_page() {
        return "pc/scene_list";
    }

    @ResponseBody
    @RequiresPermissions("deletePublish")
    @RequestMapping("deletePublish")
    public Map<String, Object> deletePublish(int pd_id) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("code", 0);
        map.put("msg", "删除成功");
        int status = managerService.deletePublishByPd_id(pd_id);
        if (status == 0) {
            map.put("msg", "删除失败");
            map.put("code", -1);
            return map;
        }
        return map;
    }

    //    删除场景
    @ResponseBody
    @RequiresPermissions("deletePublish")
    @RequestMapping("deleteScene")
    public Map<String, Object> deleteScene(int pd_id) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("code", 0);
        map.put("msg", "删除成功");
        int status = managerService.deleteScene(pd_id);
        if (status == 0) {
            map.put("msg", "删除失败");
            map.put("code", -1);
            return map;
        }
        return map;
    }

    @RequiresPermissions("edit_publish")
    @RequestMapping("edit_publish")
    public String edit_publish(int pd_id, ModelMap map) {
        map.addAttribute("publish", managerService.getPublishInfo(pd_id));
        map.addAttribute("publishInterficeName", "updatePublishInfo");
        map.addAttribute("publishImgInterficeName", "updatePublishImg");
        return "pc/publishInfo";
    }

    @RequiresPermissions("edit_publish")
    @RequestMapping("edit_scene")
    public String edit_scene(int pd_id, ModelMap map) {
        map.addAttribute("publish", managerService.getSceneInfo(pd_id));
        map.addAttribute("publishInterficeName", "updateSceneInfo");
        map.addAttribute("publishImgInterficeName", "updateSceneImg");
        return "pc/scene";
    }

    @RequiresPermissions("edit_publish")
    @RequestMapping("updatePublishInfo")
    @ResponseBody
    public Map<String, Object> updatePublishInfo(HttpServletRequest request, int pd_id, String pd_title, String pd_content) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("code", 0);
        map.put("msg", "添加成功!");
        if (pd_id != -1) {
            if (managerService.updatePublishInfo(pd_id, pd_title, pd_content) == 0) {
                map.put("code", -1);
                map.put("msg", "修改失败！");
            }
        } else {
            //添加
            String imgName = "";
            System.out.println("开始了");
            if (request.getSession().getAttribute("newPublishimg") == null) {
                imgName = "publishImg.jpeg";
            } else {
                imgName = request.getSession().getAttribute("newPublishimg").toString();
            }
            System.out.println("最终的img=" + imgName);
            Map<String, Object> manager = (Map<String, Object>) request.getSession().getAttribute("manager");
            int manager_id = (int) manager.get("manager_id");
            if (managerService.addPublish(pd_title, pd_content, imgName, manager_id) == 0) {
                map.put("code", -1);
                map.put("msg", "添加失败");
            }
        }

        return map;
    }

    //    添加场景
    @RequiresPermissions("edit_publish")
    @RequestMapping("updateSceneInfo")
    @ResponseBody
    public Map<String, Object> updateSceneInfo(HttpServletRequest request, int pd_id, String pd_title, String pd_content) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("code", 0);
        map.put("msg", "添加成功!");
        if (pd_id != -1) {
            if (managerService.updateSceneInfo(pd_id, pd_title, pd_content) == 0) {
                map.put("code", -1);
                map.put("msg", "修改失败！");
            }
        } else {
            //添加
            String imgName = "";
            System.out.println("开始了");
            if (request.getSession().getAttribute("newSceneimg") == null) {
                imgName = "publishImg.jpeg";
            } else {
                imgName = request.getSession().getAttribute("newSceneimg").toString();
            }
            System.out.println("最终的img=" + imgName);
            Map<String, Object> manager = (Map<String, Object>) request.getSession().getAttribute("manager");
            int manager_id = (int) manager.get("manager_id");
            if (managerService.addScene(pd_title, pd_content, imgName, manager_id) == 0) {
                map.put("code", -1);
                map.put("msg", "添加失败");
            }
        }

        return map;
    }

    //修改节目图片
    @RequiresPermissions("edit_publish")
    @ResponseBody
    @RequestMapping("updatePublishImg")
    public Map<String, Object> updatePublishImg(HttpServletRequest request, MultipartFile file, int pd_id) throws FileNotFoundException {
        long t = new Date().getTime();
        String filePath = "";
        File path = new File(ResourceUtils.getURL("classpath:").getPath());
        if (!path.exists()) path = new File("");
        if (!file.isEmpty()) {
            filePath = path.getAbsolutePath() + "/static/img/publishImg/" + t + file.getOriginalFilename();
            try {
                file.transferTo(new File(filePath));
            } catch (IllegalStateException e) {
                // TODO Auto-generated catch block
                System.out.println(e);
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                System.out.println(e);
                e.printStackTrace();
            }
        }
        if (pd_id != -1) {
            int row = managerService.updatePublishImg(t + file.getOriginalFilename(), pd_id);
        } else {
            //调用添加的接口
            request.getSession().setAttribute("newPublishimg", t + file.getOriginalFilename());
        }
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("code", 0);
        map.put("msg", "");
        map.put("src", "/img/publishImg/" + t + file.getOriginalFilename());
        return map;
    }

    //修改节目图片
    @RequiresPermissions("edit_publish")
    @ResponseBody
    @RequestMapping("updateSceneImg")
    public Map<String, Object> updateSceneImg(HttpServletRequest request, MultipartFile file, int pd_id) throws FileNotFoundException {
        System.out.println("上传场景图片进来了");
        long t = new Date().getTime();
        String filePath = "";
        File path = new File(ResourceUtils.getURL("classpath:").getPath());
        if (!path.exists()) path = new File("");
        if (!file.isEmpty()) {
            filePath = path.getAbsolutePath() + "/static/img/sceneImg/" + t + file.getOriginalFilename();
            System.out.println("图片路径=" + filePath);
            try {
                file.transferTo(new File(filePath));
            } catch (IllegalStateException e) {
                // TODO Auto-generated catch block
                System.out.println(e);
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                System.out.println(e);
                e.printStackTrace();
            }
        }
        if (pd_id != -1) {
            int row = managerService.updateSceneImg(t + file.getOriginalFilename(), pd_id);
        } else {
            //调用添加的接口
            request.getSession().setAttribute("newSceneimg", t + file.getOriginalFilename());
        }
        System.out.println("添加完了");
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("code", 0);
        map.put("msg", "");
        map.put("src", "/img/sceneImg/" + t + file.getOriginalFilename());
        return map;
    }

    @RequiresPermissions("add_publish_Page")
    @RequestMapping("add_publish_Page")
    public String add_publish(ModelMap map) {
        map.addAttribute("publishInterficeName", "updatePublishInfo");
        map.addAttribute("publishImgInterficeName", "updatePublishImg");
        map.addAttribute("publish", null);
        return "pc/publishInfo";
    }

    @RequiresPermissions("add_publish_Page")
    @RequestMapping("add_scene_Page")
    public String add_scene_Page(ModelMap map) {
        map.addAttribute("publishInterficeName", "updateSceneInfo");
        map.addAttribute("publishImgInterficeName", "updateSceneImg");
        map.addAttribute("publish", null);
        return "pc/scene";
    }

    @RequiresPermissions("getPublishList")
    @ResponseBody
    @RequestMapping("searchPublish")
    public Map<String, Object> searchPublish(String title, int page, int limit) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("code", 0);
        map.put("msg", "");
        map.put("count", managerService.searchPublishCount(title));
        map.put("data", managerService.searchPublish(title, (page - 1) * limit, limit));
        return map;
    }

    //搜索场景
    @RequiresPermissions("getPublishList")
    @ResponseBody
    @RequestMapping("searchScene")
    public Map<String, Object> searchScene(String title, int page, int limit) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("code", 0);
        map.put("msg", "");
        map.put("count", managerService.searchSceneCount(title));
        map.put("data", managerService.searchScene(title, (page - 1) * limit, limit));
        return map;
    }

    @RequiresPermissions("getFeeScaleByPd_id")
    @RequestMapping("feeScaleListPage")
    public String feeScaleListPage(ModelMap map, int pd_id) {
        map.addAttribute("pd_id", pd_id);
        return "pc/feeScaleList";
    }

    @RequiresPermissions("getFeeScaleByPd_id")
    @ResponseBody
    @RequestMapping("getFeeScaleByPd_id")
    public Map<String, Object> getFeeScaleByPd_id(int pd_id, int page, int limit) {
        Map<String, Object> map = new HashMap<String, Object>();
        List<Map<String, Object>> feeScaleList = managerService.getFeeScaleByPd_id(pd_id, (page - 1) * limit, limit);
        map.put("code", 0);
        map.put("msg", "");
        map.put("count", 99999);
        map.put("data", feeScaleList);
        return map;
    }

    @RequiresPermissions("getFeeScaleByPd_id")
    @ResponseBody
    @RequestMapping("searchFeeScale")
    public Map<String, Object> searchFeeScale(int pd_id, String title, int page, int limit) {
        Map<String, Object> map = new HashMap<String, Object>();
        List<Map<String, Object>> feeScaleList = managerService.searchFeeScale(pd_id, title, (page - 1) * limit, limit);
        map.put("code", 0);
        map.put("msg", "获取成功");
        map.put("count", 99999);
        map.put("data", feeScaleList);
        return map;
    }

    @RequiresPermissions("add_feeScale")
    @ResponseBody
    @RequestMapping("add_feeScale")
    public Map<String, Object> add_feeScale(int pd_id, String publish_time, float publish_price) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("code", 0);
        map.put("msg", "获取成功");
        if (managerService.add_feeScale(pd_id, publish_time, publish_price) == 1) {
            map.put("code", 0);
            map.put("msg", "获取成功");
            return map;
        }
        return map;
    }

    @RequiresPermissions("deleteFeeScale")
    @ResponseBody
    @RequestMapping("deleteFeeScale")
    public Map<String, Object> deleteFeeScale(int feeScale_id) {
        Map<String, Object> map = new HashMap<String, Object>();
        if (managerService.deleteFeaScale(feeScale_id) == 1) {
            map.put("code", 0);
        } else {
            map.put("code", -1);
        }
        return map;
    }

    @RequiresPermissions("actor_management_page")
    @RequestMapping("actor_management_page")
    public String actor_management_page() {
        return "pc/actor_list";
    }

    @ResponseBody
    @RequestMapping("getActorList")
    public Map<String, Object> getActorList(int page, int limit) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("code", 0);
        map.put("msg", "获取成功");
        map.put("count", managerService.getActorListCount());
        map.put("data", managerService.getActorList((page - 1) * limit, limit));
        return map;
    }

    @RequiresPermissions("actor_management_page")
    @ResponseBody
    @RequestMapping("searchActor")
    public Map<String, Object> searchActor(String title, int page, int limit) {

        Map<String, Object> map = new HashMap<String, Object>();
//        List<Map<String,Object>>feeScaleList=managerService.searchFeeScale(pd_id,title,(page-1)*limit,limit);
        map.put("code", 0);
        map.put("msg", "获取成功");
        map.put("count", managerService.searchActorCount(title));
        map.put("data", managerService.searchActor(title, (page - 1) * limit, limit));
        return map;
    }

    //edit_actor_page
    @RequiresPermissions("edit_actor_page")
    @RequestMapping("edit_actor_page")
    public String edit_actor_page(int actor_id, ModelMap map) {
        map.addAttribute("actor", managerService.getActorInfo(actor_id));
        map.addAttribute("updateInfoInterfice", "updateActorInfo");
        map.addAttribute("updateImgInterfice", "updateActorImg");
        return "pc/actorInfo";
    }

    @RequiresPermissions("add_actor")
    @RequestMapping("add_actor")
    public String add_actor(ModelMap map) {
        map.addAttribute("actor", null);
        map.addAttribute("updateInfoInterfice", "updateActorInfo");
        map.addAttribute("updateImgInterfice", "updateActorImg");
        return "pc/actorInfo";
    }

    @RequiresPermissions("edit_actor_page")
    @RequestMapping("updateActorInfo")
    @ResponseBody
    public Map<String, Object> updateActorInfo(@RequestParam Map actor, HttpServletRequest request) {
        Map<String, Object> map = new HashMap<String, Object>();
        Map<String, Object> manager = (Map<String, Object>) request.getSession().getAttribute("manager");
        int manager_id = (int) manager.get("manager_id");
        if (Integer.parseInt(actor.get("actor_id").toString()) == -1) {
            String img = "";
            if (request.getSession().getAttribute("newActorImg") == null) {
                img = "actorImg.jpg";
            } else {
                img = request.getSession().getAttribute("newActorImg").toString();
            }
            actor.put("actor_img", img);
            actor.put("manager_id", manager_id);
            if (managerService.add_actor(actor) == 1) {
                map.put("code", 0);
                map.put("msg", "添加成功");
            } else {
                map.put("code", -1);
                map.put("msg", "添加失败");
            }
            return map;
        }
        if (managerService.update_actor(actor) == 1) {
            map.put("code", 0);
            map.put("msg", "修改成功");
        } else {
            map.put("code", -1);
            map.put("msg", "修改失败");
        }
        return map;
    }

    //修改演员图片
    @RequiresPermissions("edit_actor_page")
    @ResponseBody
    @RequestMapping("updateActorImg")
    public Map<String, Object> updateActorImg(HttpServletRequest request, MultipartFile file, int actor_id) throws FileNotFoundException {
        long t = new Date().getTime();
        String filePath = "";
        File path = new File(ResourceUtils.getURL("classpath:").getPath());
        if (!path.exists()) path = new File("");
        if (!file.isEmpty()) {
            filePath = path.getAbsolutePath() + "/static/img/actorImg/" + t + file.getOriginalFilename();
            try {
                file.transferTo(new File(filePath));
            } catch (IllegalStateException e) {
                // TODO Auto-generated catch block
                System.out.println(e);
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                System.out.println(e);
                e.printStackTrace();
            }
        }
        int row = 1;
        System.out.println(actor_id);
        System.out.println(t + file.getOriginalFilename());
        if (actor_id != -1) {
//            int row=managerService.updatePublishImg(t+file.getOriginalFilename(),pd_id);
            if (managerService.updateActorImg(t + file.getOriginalFilename(), actor_id) != 1) {
                row = 0;
            }
        } else {
            //调用添加的接口
            request.getSession().setAttribute("newActorImg", t + file.getOriginalFilename());
        }
        Map<String, Object> map = new HashMap<String, Object>();
        if (row == 1) {
            map.put("code", 0);
            map.put("msg", "修改成功");
        } else {
            map.put("code", -1);
            map.put("msg", "修改失败");
        }
        map.put("src", "/img/actorImg/" + t + file.getOriginalFilename());
        return map;
    }

    @RequiresPermissions("deleteActor")
    @ResponseBody
    @RequestMapping("deleteActor")
    public Map<String, Object> deleteActor(int actor_id) {
        Map<String, Object> map = new HashMap<String, Object>();
        if (managerService.deleteActor(actor_id) == 1) {
            map.put("code", 0);
        } else {
            map.put("code", -1);
        }
        return map;
    }

    @RequiresPermissions("getActorListByPublish_id")
    @ResponseBody
    @RequestMapping("getActorListByPublish_id")
    public Map<String, Object> getActorListByPublish_id(int publish_id, int page, int limit) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("code", 0);
        map.put("msg", "获取成功");
        map.put("count", managerService.getActorListByPublish_idCount());
        map.put("data", managerService.getActorListByPublish_id(publish_id, (page - 1) * limit, limit));
        System.out.println(map);
        return map;
    }

    @RequiresPermissions("getActorListByPublish_id")
    @RequestMapping("publish_actor_list")
    public String publish_actor_list(int pd_id, ModelMap map) {
        map.addAttribute("publish_id", pd_id);
        return "pc/publish_actor_list";
    }

    @RequiresPermissions("getActorListByPublish_id")
    @ResponseBody
    @RequestMapping("searchGetActorListByPublish_id")
    public Map<String, Object> searchGetActorListByPublish_id(String title, int publish_id, int page, int limit) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("code", 0);
        map.put("msg", "获取成功");
        map.put("count", 99999);
        map.put("data", managerService.searchGetActorListByPublish_id(title, publish_id, (page - 1) * limit, limit));
        return map;
    }

    @RequiresPermissions("getActorListByPublish_id")
    @ResponseBody
    @RequestMapping("cancelActorOfPublish")
    public Map<String, Object> cancelActorOfPublish(int publish_id, int actor_id) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("code", 0);
        map.put("msg", "取消成功");
        if (managerService.cancelActorOfPublish(publish_id, actor_id) != 1) {
            map.put("code", -1);
            map.put("msg", "获取失败");
            return map;
        }
        return map;
    }

    @RequiresPermissions("getNewOrderList")
    @ResponseBody
    @RequestMapping("getNewOrderList")
    public Map<String, Object> getNewOrderList(int page, int limit) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("code", 0);
        map.put("msg", "获取成功");
        map.put("count", managerService.getnewOderListCount());
        map.put("data", managerService.getnewOderList((page - 1) * limit, limit));
        return map;
    }

    @RequiresPermissions("getNewOrderList2")
    @ResponseBody
    @RequestMapping("getNewOrderList2")
    public Map<String, Object> getNewOrderList2(int page, int limit) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("code", 0);
        map.put("msg", "获取成功");
        map.put("count", managerService.getnewOderList2Count());
        map.put("data", managerService.getnewOderList2((page - 1) * limit, limit));
        return map;
    }

    @RequiresPermissions("getNewOrderList3")
    @ResponseBody
    @RequestMapping("getNewOrderList3")
    public Map<String, Object> getNewOrderList3(int page, int limit) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("code", 0);
        map.put("msg", "获取成功");
        map.put("count", managerService.getnewOderList3Count());
        map.put("data", managerService.getnewOderList3((page - 1) * limit, limit));
        return map;
    }

    @RequiresPermissions("getNewOrderList4")
    @ResponseBody
    @RequestMapping("getNewOrderList4")
    public Map<String, Object> getNewOrderList4(int page, int limit) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("code", 0);
        map.put("msg", "获取成功");
        map.put("count", managerService.getnewOderList4Count());
        map.put("data", managerService.getnewOderList4((page - 1) * limit, limit));
        return map;
    }

    //
    @RequiresPermissions("getNewOrderList")
    @RequestMapping("newOrderPage")
    public String newOrderPage(ModelMap map) {
        return "pc/newOrderList";
    }

    @RequiresPermissions("getNewOrderList2")
    @RequestMapping("newOrderPage2")
    public String newOrderPage2(ModelMap map) {
        return "pc/newOrderList2";
    }

    @RequiresPermissions("getNewOrderList3")
    @RequestMapping("newOrderPage3")
    public String newOrderPage3(ModelMap map) {
        return "pc/newOrderList3";
    }

    @RequiresPermissions("getNewOrderList4")
    @RequestMapping("newOrderPage4")
    public String newOrderPage4(ModelMap map) {
        return "pc/newOrderList4";
    }


    @RequiresPermissions("orderInfoPage")
    @RequestMapping("orderInfoPage")
    public String orderInfoPage(ModelMap map, int order_id) {
        map.addAttribute("orderInfo", managerService.getActorListByOrder_id(order_id));
        map.addAttribute("actorList", managerService.getActorForFeeScaleByOrder_id(order_id));
        System.out.println(map);
        return "pc/orderInfo";
    }

    //    @ResponseBody
//    @RequestMapping("cancelActor_idByFeeScale_id")
//    public Map<String,Object>cancelActor_idByFeeScale_id(int feeScale_id){
//        Map<String,Object>map=new HashMap<String, Object>();
//        map.put("code",0);
//        map.put("msg","已取消");
//        if (managerService.cancelActorByFeeScale_id(feeScale_id)!=1){
//            map.put("code",-1);
//            map.put("msg","发送错误");
//        }
//        return map;
//    }
    @RequiresPermissions("getOrderSetActorList")
    @ResponseBody
    @RequestMapping("getOrderSetActorList")
    public Map<String, Object> getOrderSetActorList(int order_feeScale_id, int publish_id, int page, int limit) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("code", 0);
        map.put("msg", "获取成功");
        map.put("count", 99999);
        map.put("data", managerService.getActorListSetOrderByPublish_id(order_feeScale_id, publish_id, (page - 1) * limit, limit));
        return map;
    }

    @RequiresPermissions("getOrderSetActorList")
    @ResponseBody
    @RequestMapping("searchOrderSetActorList")
    public Map<String, Object> searchOrderSetActorList(String title, int publish_id, int page, int limit) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("code", 0);
        map.put("msg", "获取成功");
        map.put("count", 99999);
        map.put("data", managerService.searchOrderSetActorList(title, publish_id, (page - 1) * limit, limit));
        return map;
    }

    @RequiresPermissions("getOrderSetActorList")
    @RequestMapping("getActorListByPublish_id_page")
    public String getActorListByPublish_id_page(ModelMap map, int publish_id, int order_feeScale_id, int order_id) {
//        map.addAttribute("orderInfo",managerService.getActorListByOrder_id(order_id));
        map.addAttribute("publish_id", publish_id);
        map.addAttribute("order_feeScale_id", order_feeScale_id);
        map.addAttribute("order_id", order_id);
        return "pc/order_set_actor_list";
    }

    @RequiresPermissions("getOrderSetActorList")
    @ResponseBody
    @RequestMapping("orderSetActorByFeeScale_id")
    public Map<String, Object> orderSetActorByFeeScale_id(int order_feeScale_id, int actor_id) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("code", 0);
        map.put("msg", "安排成功");
        if (managerService.orderSetActorByFeeScale_id(actor_id, order_feeScale_id) != 1) {
            map.put("code", -1);
            map.put("msg", "发生错误");
        }
        return map;
    }

    @RequiresPermissions("getOrderSetActorList")
    @ResponseBody
    @RequestMapping("cancelActorToOrder")
    public Map<String, Object> cancelActorToOrder(int order_feeScale_id, int actor_id) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("code", 0);
        map.put("msg", "取消成功");
        if (managerService.cancelActorToOrder(order_feeScale_id, actor_id) != 1) {
            map.put("code", -1);
            map.put("msg", "取消失败");
        }
        return map;
    }

    @RequestMapping("updateOrderStatus")
    public String updateOrderStatus(int order_id, int order_status) throws ClientException, InterruptedException {
        managerService.updateOrderStatusByOrder_id(order_status, order_id);
        return "pc/newOrderList";
    }

    @ResponseBody
    @RequestMapping("getOrder_publish_count")
    public List<Map<String, Object>> getOrder_publish_count() {
        return managerService.getOrder_publish_count();
    }

    //    写到755行了
    @ResponseBody
    @RequestMapping("getAllPublish_order_count")
    public Map<String, Object> getAllPublish_order_count() {
        Map<String, Object> map = new HashMap<String, Object>();
        List<Map<String, Object>> ls = managerService.getAllPublish_order_count();
        List<String> name = new ArrayList<>();
        List<String> data = new ArrayList<>();
        for (int i = 0; i < ls.size(); i++) {
            name.add(ls.get(i).get("pd_title").toString());
            if (ls.get(i).get("order_id") == null) {
                data.add("0");
            } else {
                data.add(ls.get(i).get("count").toString());
            }

        }
        map.put("name", name);
        map.put("data", data);
        System.out.println(map);
        return map;
    }

    @ResponseBody
    @RequestMapping("niandingdanliang")
    public Map<String, Object> niandingdanliang(String nian) {
        Map<String, Object> map = new HashMap<String, Object>();
        List<String> date = new ArrayList<>();
        List<Integer> data = new ArrayList<>();
        for (int i = 1; i <= 12; i++) {
            date.add(i + "月份");
            data.add(managerService.getOrderCountByYearAndMonth(nian + "-" + i));
        }
        map.put("date", date);
        map.put("data", data);
        return map;
    }

    @ResponseBody
    @RequestMapping("deletePublishByOder_feeScale_id")
    public Map<String, Object> deletePublishByOder_feeScale_id(int order_feeScale_id) {
        Map<String, Object> map = new HashMap<>();
        if (managerService.deleteOrder_feeScaleByOrder_feeScale_id(order_feeScale_id) != 1) {
            map.put("code", -1);
            map.put("msg", "删除失败");
        }
        map.put("code", 0);
        map.put("msg", "删除成功");
        return map;
    }

    @ResponseBody
    @RequestMapping("searchOderList")
    public Map<String, Object> searchOderList(String title, int page, int limit, int order_status) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("code", 0);
        map.put("msg", "获取成功");
        map.put("count", managerService.searchOderListCount(title, order_status));
        map.put("data", managerService.searchOderList(title, (page - 1) * limit, limit, order_status));
        return map;
    }

    @ResponseBody
    @RequestMapping("getActorLishiOrder")
    public Map<String, Object> getActorLishiOrder(int page, int limit, int actor_id) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("code", 0);
        map.put("msg", "获取成功");
        map.put("count", managerService.getActorLishiOrderCount(actor_id));
        map.put("data", managerService.getActorLishiOrder((page - 1) * limit, limit, actor_id));
        return map;
    }

    @RequestMapping("toActorLishiOrder")
    public String toActorLishiOrder(int actor_id, ModelMap map) {
        map.addAttribute("actor_id", actor_id);
        return "pc/actor_lishi_order";
    }


    @ResponseBody
    @RequestMapping("searchActorOderList")
    public Map<String, Object> searchActorOderList(String title, int page, int limit, int actor_id) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("code", 0);
        map.put("msg", "获取成功");
        map.put("count", 99999);
        map.put("data", managerService.searchOderList(title, (page - 1) * limit, limit, actor_id));
        return map;
    }

    @RequestMapping("sendMessageSitting")
    public String sendMessageSitting() {
        return "pc/sendMessageSitting";
    }

    @RequestMapping("FindAllManagerList2Page")
    public String FindAllManagerList2Page() {
        return "pc/manager_listOfSendMessage";
    }

    @ResponseBody
    @RequestMapping("getSendMessageManagerList")
    public Map<String, Object> getSendMessageManagerList() {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("code", 0);
        map.put("msg", "获取成功");
        map.put("count", 99999);
        map.put("data", managerService.getSendMessageManagerList());
        return map;
    }


    @RequiresPermissions("FindAllManagerList")
    @ResponseBody
    @RequestMapping("searchManager2")
    public Map<String, Object> searchManager2(String title, int page, int limit) {
        Map<String, Object> map = new HashMap<String, Object>();
//        System.out.println(limit);
//        System.out.println(page);
        map.put("code", 0);
        map.put("msg", "");
        map.put("count", managerService.searchManagerCount2(title));
        SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd  HH:mm:ss");
        List<Map<String, Object>> searchManagerList = managerService.searchManager2((page - 1) * limit, limit, title);
        for (int i = 0; i < searchManagerList.size(); i++) {
            searchManagerList.get(i).put("manager_addtime", sf.format((Date) searchManagerList.get(i).get("manager_addtime")));
        }
        map.put("data", searchManagerList);
        return map;
    }

    @ResponseBody
    @RequestMapping("delteSendMessageManager")
    public Map<String, Object> delteSendMessageManager(int id) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("code", 0);
        map.put("msg", "删除成功");
//        map.put("data",managerService.getSendMessageManagerList());
        if (managerService.deleteSendMessageManager(id) != 1) {
            map.put("code", -1);
            map.put("msg", "发生错误");
            return map;
        }
        return map;
    }

    @ResponseBody
    @RequestMapping("addSendMessageManager")
    public Map<String, Object> addSendMessageManager(int manager_id) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("code", 0);
        map.put("msg", "添加成功");
//        map.put("data",managerService.getSendMessageManagerList());
        if (managerService.addSendMessageManager(manager_id) != 1) {
            map.put("code", -1);
            map.put("msg", "发生错误");
            return map;
        }
        return map;
    }
}
